<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../../commons/taglibs.jsp"%>
<%@ include file="../../commons/list.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta charset="utf-8">
  <title>汽车分期</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <style type="text/css">
  	input{
  		width: 200px;
  		display: inline;
  	}
  </style>
	<link rel="stylesheet" href="<%=basePath%>common/plugins/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="<%=basePath%>common/plugins/zTree/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>common/plugins/zTree/js/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="<%=basePath%>common/plugins/zTree/js/jquery.ztree.excheck.js"></script>
	
</head>

<body>
<div>
	<div style="padding: 50px;padding-top: 30px">
		<form class="layui-form layui-form-pane"  action="">
		<input type="hidden" id='entityId' name='entityId' value="${sysRole.id }">
		<input type="hidden" id='menuIds' lay-filter='menuIds' name='menuIds' value="123123">
		  <div class="layui-form-item" style="width: 85%;padding-left: 20px">
		    <label class="layui-form-label">角色名称</label>
		    <div class="layui-input-block" >
		     	<input type="text" name="rolename" id='rolename' value="${sysRole.rolename }" required  lay-verify="required" placeholder="请输入角色名称" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item" style="width: 85%;padding-left: 20px;padding-top: 15px;">
		  		<div style="height:200px; overflow-y:scroll; border:1px #ccc solid;text-align: center; width: 100%;">
			  		<!-- 展示菜单权限树 -->
			  		<ul id="treeDemo" class="ztree"></ul>
		  		</div>
		  </div>
		  
		  <div class="layui-form-item" style="width: 85%;padding-left: 150px;padding-top: 30px">
		    <div class="layui-input-block">
		      <button class="layui-btn" id='tjsub' lay-submit lay-filter="formDemo">立即提交</button>
		      <a class="layui-btn" onclick="closeWindow()"><i class="layui-icon">&#xe65c;</i>返回</a>
		    </div>
		  </div>
		  
		</form>
	</div>
 </div>
<script>
//Demo
layui.use('form', function(){
  var form = layui.form;
  //监听提交
  form.on('submit(formDemo)', function(data){
	  var zTreeOjb = $.fn.zTree.getZTreeObj("treeDemo");  //ztree的Id  zTreeId
	  var checkedNodes = zTreeOjb.getCheckedNodes();
	  var info = JSON.stringify(checkedNodes);
	  var json = JSON.parse(info);
	  var menuIds = '';
	  $.each(json, function(iz, obj) {
		  menuIds += ','+obj.id;
	  });
	  var entityId = $("#entityId").val();
	  var rolename = $("#rolename").val();
	  var data = {'entityId':entityId,'menuIds':menuIds,'rolename':rolename};
	  //提交成功后禁用按钮
	  $("#tjsub").css("pointer-events","none"); 
	  $.post('<%=basePath%>controller/sysRole/save',data,function(data){
		  if(data == '1'){
			  $("#tjsub").css("pointer-events","auto");
			  layer.msg('提交失败', {time:1000});
		  }
		  if(data == '0'){
			  layer.msg('提交成功', {time:1000});
			  setTimeout("layer.closeAll()",1000);
			  //window.setTimeout(refreshCount, 1000 * 5);
			  //调用刷新页面
			  setTimeout("parent.location.reload()",2000);
		  }
	  })
    return false;
  });
});
//返回按钮事件
function closeWindow(){
        var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
} 
</script>
<SCRIPT type="text/javascript">
		var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};

		var zNodes =${sysMenuList};

		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		});
	</SCRIPT>
</body>
</html>
